from rest_framework.response import Response
from rest_framework.permissions import IsAdminUser,DjangoModelPermissions
from rest_framework.viewsets import ModelViewSet
from goods.models import SPUSpecification,SPU
from ..serializers.specs import SPUSpecificationSerializer,SPUSerialzier
from ..utils import PageNum

class SpecsView(ModelViewSet):
    # 指定查询集
    queryset = SPUSpecification.objects.all()
    # 指定序列化器
    serializer_class = SPUSpecificationSerializer
    # 指定权限
    permission_classes = [IsAdminUser,DjangoModelPermissions]
    # 指定分页器
    pagination_class = PageNum

    # 获取spu商品数据
    def simple(self,request):
        # 1、查询所有spu表数据
        spus = SPU.objects.all()
        # 2、序列化返回
        ser = SPUSerialzier(spus, many=True)

        return Response(ser.data)